package io.xxx.mario.robot;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class WechatyPuppetService {

    @Resource
    private WechatyPuppetMapper wechatyPuppetMapper;

    public Page<WechatyPuppet> getPage(Pageable pageable, String name, Boolean used) {
        LambdaQueryWrapper<WechatyPuppet> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(name)) {
            wrapper.eq(WechatyPuppet::getName, name);
        }
        if (used != null) {
            wrapper.eq(WechatyPuppet::isUsed, used);
        }
        Page<WechatyPuppet> page = new Page<>(pageable.getPageNumber(), pageable.getPageSize());
        return wechatyPuppetMapper.selectPage(page, wrapper);
    }

    public void useToken(Long puppetId) {
        wechatyPuppetMapper.useToken(puppetId);
    }

    /**
     * 如果
     */
    public void save() {

    }
}
